package com.gxkj.projects.myshopx.dao;

import com.gxkj.common.hibernate.HibernateBaseRepositoryImpl;
import com.gxkj.common.utils.ListPager;
import com.gxkj.projects.myshopx.entitys.UserRank;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

@Repository
public class UserRankDaoImpl extends HibernateBaseRepositoryImpl {

    public ListPager<UserRank> doPageHQL(int pagenNo, int pageSize, UserRank entity){
        ListPager<UserRank> pager = new ListPager<UserRank>();
        pager.setPageNo(pagenNo);
        pager.setRowsPerPage(pageSize);
        String hql  = " from UserRank ur  ";
        Map<String,Object> param = new HashMap<String,Object>();
        hql += " where isDel  = :isDel ";
        if(entity == null ||   entity.getIsDel() == 0  ){
            param.put("isDel", 0);
        }else {
            param.put("isDel", 1);
        }
        if(entity != null){
            if(StringUtils.isNoneBlank(entity.getRankName())){
                hql += " and rankName  like :rankName ";
                param.put("rankName", "%"+entity.getRankName()+"%");
            }
        }
        return  this.selectPageByHql(hql,param,pager);
    }
}
